import sqlite3 as db
import sys
import os
import exceptions


db_name = "robot.db"

db_is_new = not os.path.exists(db_name)

con  = None

with con:
    print ("Cheking database...")
    con = db.connect(db_name)
    if db_is_new:
        print ("Creating database...")
    else:
        print("Database exists! Creating tables...")
    con = db.connect(db_name)
    cur = con.cursor()
    print("Creating STATIONS table... ")
    cur.execute("CREATE TABLE stations(id INT PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(20)")
    print("Creating ROBOTS table...")
    cur.execute("CREATE TABLE robots (id INT PRIMARY KEY NOT NULL AUTOINCREMENT, name VARCHAR(20), x INT, y INT, z INT, station REFERENCES stations(id)")
    print("Creating SHARE table...")
    cur.execute("CREATE TABLE share(id INT PRIMARY KEY NOT NULL AUTOINCREMENT,, station REFERENCES stations(id)")


    
    
    
